import { myPost } from '@/util/request'
import http from '@/util/request'
import { API_SERVER } from '../service'

const ADMIN_SERVER = `${API_SERVER}/v2`

// 我的知识库
export const myKnowledge = {
  typeList: (data) => myPost(`${ADMIN_SERVER}/kbs/type/list`, data),
  typeAdd: (data) => myPost(`${ADMIN_SERVER}/kbs/type/add`, data),
  typeEdit: (data) => myPost(`${ADMIN_SERVER}/kbs/type/edit`, data),
  typeDelete: (data) => myPost(`${ADMIN_SERVER}/kbs/type/delete`, data),

  catePage: (data) => myPost(`${ADMIN_SERVER}/xiaoe/kb/index`, data),
  list: (data) => myPost(`${ADMIN_SERVER}/agent/findall/knowledge`, data),
  check: (data) => myPost(`${ADMIN_SERVER}/xiaoe/kb/check`, data),
  cateAdd: (data) => myPost(`${ADMIN_SERVER}/xiaoe/kb/add`, data),
  cateEdit: (data) => myPost(`${ADMIN_SERVER}/xiaoe/kb/edit`, data),
  cateUpload: (data) => {
    const formData = new FormData()
    for(const key in data) {
      formData.append(key, data[key])
    }

    return http({
      url: `${ADMIN_SERVER}/xiaoe/upload`,
      method: 'post',
      headers: {
        'content-type': 'multipart/form-data'
      },
      timeout: 1500000,
      data: formData
    })
  },
  cateDelete: (data) => myPost(`${ADMIN_SERVER}/xiaoe/delete`, data),
  cateDetail: (data) => myPost(`${ADMIN_SERVER}/xiaoe/kb/detail`, data),
  findall: (data) => myPost(`${ADMIN_SERVER}/model/findall`, data),
  isenable: (data) => myPost(`${ADMIN_SERVER}/knowledge/slice/isenable`, data),
  sliceFindall: (data) => myPost(`${ADMIN_SERVER}/knowledge/slice/findall`, data),
  searchFindall: (data) => myPost(`${ADMIN_SERVER}/knowledge/slice/search`, data),
  sliceEdit: (data) => myPost(`${ADMIN_SERVER}/knowledge/slice/edit`, data),

  page: (data) => myPost(`${ADMIN_SERVER}/xiaoe/kb/findfilepage`, data),
  fileedit: (data) => myPost(`${ADMIN_SERVER}/xiaoe/kb/fileedit`, data),
  updateIsenable: (data) => myPost(`${ADMIN_SERVER}/xiaoe/kb/update/isenable`, data),
  knowledgeedit: (data) => myPost(`${ADMIN_SERVER}/xiaoe/kb/knowledgeedit`, data),
  fileDelete: (data) => myPost(`${ADMIN_SERVER}/xiaoe/kb/file/delete`, data),
}

export const fileContent = {
  download: (data) => {
    return http({
      url: `${ADMIN_SERVER}/knowledge/slice/download`,
      method: 'post',
      responseType: 'blob',
      timeout: 1500000,
      data
    })
  },
  fileDetail: (data) => myPost(`${ADMIN_SERVER}/knowledge/slice/file/detail`, data),
  detail: (data) => myPost(`${ADMIN_SERVER}/knowledge/slice/qa/detail`, data),
  insert: (data) => myPost(`${ADMIN_SERVER}/knowledge/slice/insert`, data),
  delete: (data) => myPost(`${ADMIN_SERVER}/knowledge/slice/qa/delete`, data),
}

export const faq = {
  typeAdd: (data) => myPost(`${ADMIN_SERVER}/xiaoe/cate/add`, data),
  typeEdit: (data) => myPost(`${ADMIN_SERVER}/xiaoe/cate/edit`, data),
  typeDel: (data) => myPost(`${ADMIN_SERVER}/xiaoe/cate/delete`, data),
  
  page: (data) => myPost(`${ADMIN_SERVER}/xiaoe/topic/page`, data),
  add: (data) => myPost(`${ADMIN_SERVER}/xiaoe/topic/add`, data),
  edit: (data) => myPost(`${ADMIN_SERVER}/xiaoe/topic/edit`, data),
  delete: (data) => myPost(`${ADMIN_SERVER}/xiaoe/topic/delete`, data),
  detail: (data) => myPost(`${ADMIN_SERVER}/xiaoe/topic/detail`, data),
  expids: (data) => {
    return http({
      url: `${ADMIN_SERVER}/xiaoe/topic/expids`,
      method: 'post',
      responseType: 'blob',
      timeout: 1500000,
      data
    })
  },
  impsave: (data) => {
    const formData = new FormData()
    for(const key in data) {
      formData.append(key, data[key])
    }

    return http({
      url: `${ADMIN_SERVER}/xiaoe/topic/impsave`,
      method: 'post',
      headers: {
        'content-type': 'multipart/form-data'
      },
      timeout: 1500000,
      data: formData
    })
  },
}
